/**
 * 存储工具
 */

var token = 'hiseeToken'
var Authorization = 'Authorization'
var accountInfo = 'accountInfo'
var callNumber = 'callNumber'
var doctorRegisterInfo = 'doctorRegisterInfo'
var doctorAuthInfo = 'doctorAuthInfo'
var failMsgArr = 'failMsgArr'
var saveMsgArr = 'saveMsgArr'
var userInfo = 'userInfo'
var cantact = 'cantact'
var source = 'source'
var apt_id = 'apt_id'
var isreal = 'isreal'
var status = 'status'
/**
 * 存储token，用于后台恢复用户
 * @param value 登录响应中hisee_token字段
 */
function setToken(value) {
  if (value == null) {
    return mpvue.removeStorage({key: token})
  }
  return mpvue.setStorageSync(token, value)
}

/**
 * 获取token，写入到每一个请求到head中
 * @returns {any | string}
 */
function getToken() {
  return mpvue.getStorageSync(token)
}
function setAuthorization(value) {
  if (value == null) {
    return mpvue.removeStorage({key: Authorization})
  }
  return mpvue.setStorageSync(Authorization, value)
}
function getAuthorization() {
  return mpvue.getStorageSync(Authorization)
}
/**
 * 设置账号密码信息，用于后面token过期时自动登录
 * @param value
 */
function setAccountInfo(value) {
  if (value == null) {
    return mpvue.removeStorage({key: accountInfo})
  }
  return mpvue.setStorageSync(accountInfo, JSON.stringify(value))
}

/**
 * 获取账号密码信息，用于token过期时自动登录
 * @returns {any | string}
 */
function getAccountInfo() {
  let accountInfoStr = mpvue.getStorageSync(accountInfo)
  if (accountInfoStr === '') {
    return null
  }
  return JSON.parse(accountInfoStr)
}

/**
 * 设置小鱼互联callNumber,用于加入会议使用
 * @param callNumber
 */
function setSmallFishCallNumber(value) {
  if (value == null) {
    return mpvue.removeStorage({key: callNumber})
  }
  return mpvue.setStorageSync(callNumber, value)
}

/**
 * 获取小鱼互联callNumber
 */
function getSmallFishCallNumber() {
  return mpvue.getStorageSync(callNumber)
}

/**
 * 保存医生注册填写信息
 * @param info
 */
function setDoctorRegisterInfo(info) {
  if (info == null) {
    return mpvue.removeStorage({key: doctorRegisterInfo})
  }
  return mpvue.setStorageSync(doctorRegisterInfo, JSON.stringify(info))
}

/**
 * 恢复医生注册填写信息
 * @returns {null|any}
 */
function getDoctorRegisterInfo() {
  let info = mpvue.getStorageSync(doctorRegisterInfo)
  if (!info) {
    return null
  }
  return JSON.parse(info)
}


/**
 * 保存医生认证填写信息
 * @param info
 */
function setDoctorAuthInfo(info) {
  if (info == null) {
    return mpvue.removeStorage({key: doctorAuthInfo})
  }
  return mpvue.setStorageSync(doctorAuthInfo, JSON.stringify(info))
}

/**
 * 恢复医生认证填写信息
 * @returns {null|any}
 */
function getDoctorAuthInfo() {
  let info = mpvue.getStorageSync(doctorAuthInfo)
  if (!info) {
    return null
  }
  return JSON.parse(info)
}
function setWxInfo(value) {
  if (value == null) {
    return mpvue.removeStorage({key: wxInfo})
  }
  return mpvue.setStorageSync('wxInfo', JSON.stringify(value))
}
function getWxInfo() {
  let info = mpvue.getStorageSync('wxInfo')
  if (!info) {
    return null
  }
  return JSON.parse(info)
}
/**
 * 保存本地消息
 * @param info
 */
function setLocalMsg(msgs) {
  console.log('设置本地消息',msgs)
  if (msgs != null && msgs.length>0) {
    console.log('设置本地消息',msgs)
    mpvue.setStorageSync(failMsgArr, msgs)//写入存储
  }else {
    mpvue.setStorageSync(failMsgArr, [])//写入存储
  }

}

/**
 * 获取本地消息
 * @returns {null|any}
 */
function getLocalMsg() {
  let arrStr = mpvue.getStorageSync(failMsgArr)
  if (!arrStr) {
    arrStr= []
  }
  console.log('获取本地消息',arrStr)
  return arrStr
}
// 保存未发送完的信息
function saveMsg(arr) {
  if (arr == null) {
    return mpvue.removeStorage({key: saveMsgArr})
  }
  return mpvue.setStorageSync(saveMsgArr, JSON.stringify(arr))
}
// 获取未发送完的信息
function getMsg() {
  let arr = mpvue.getStorageSync(saveMsgArr)
  if (!arr) {
    return null
  }
  return JSON.parse(arr)
}

// 保存身份证信息
function setUserres(value) {
  if (value == null) {
    return mpvue.removeStorage({key: userInfo})
  }
  return mpvue.setStorageSync(userInfo, value)
}
// 获取身份证信息
function getUserres() {
  return mpvue.getStorageSync(userInfo)
}
// 保存就诊人信息
function setContact(value) {
  if (value == null) {
    return mpvue.removeStorage({key: cantact})
  }
  return mpvue.setStorageSync(cantact, value)
}
// 获取就诊人信息
function getContact() {
  return mpvue.getStorageSync(cantact)
}
// 保存来源
function setSouruce(value) {
  if (value == null) {
    return mpvue.removeStorage({key: source})
  }
  return mpvue.setStorageSync(source, value)
}
// 获取就诊人信息
function getSouruce() {
  return mpvue.getStorageSync(source)
}
// 储存删除获取apt_id
function setAptId(value) {
  return mpvue.setStorageSync(apt_id, value)
}
function getAptId(value) {
  return mpvue.getStorageSync(apt_id)
}
function removeAptId(value) {
  return mpvue.removeStorage({key: apt_id})
}
function setCardeStatus(value) {
  if (value == null) {
    return mpvue.removeStorage({status: value})
  }
  return mpvue.setStorageSync(status, value)
}
function getCardeStatus() {
  return mpvue.getStorageSync(status)
}
// 页面返回带参数
function setBackParam(value) {
  return mpvue.setStorageSync(isreal, value)
}
function getBackParam(value) {
  return mpvue.getStorageSync(isreal)
}
function removeBackParam(value) {
  return mpvue.removeStorage({key: isreal})
}
// 选择就诊人
function setNowCommon(value) {
  return mpvue.setStorageSync('commonId', value)
}
function getNowCommon(value) {
  return mpvue.getStorageSync('commonId')
}
function removeNowCommon(value) {
  return mpvue.removeStorage({key: 'commonId'})
}
// 查询订单列表
function setNowAppointType(value) {
  return mpvue.setStorageSync('appointType', value)
}
function getNowAppointType() {
  return mpvue.getStorageSync('appointType')
}
function removeAppointType() {
  return mpvue.removeStorage({key: 'appointType'})
}
// 设置导航栏自定义头部
function setNavBarInfo(value) {
  return mpvue.setStorageSync('navBarInfo', value)
}
function getNavBarInfo() {
  return mpvue.getStorageSync('navBarInfo')
}
// 电子票据地址
function getInvoiceUrl() {
  return mpvue.getStorageSync('invoiceUrl')
}
export default {
  getInvoiceUrl,
  setToken,
  getToken,
  setAuthorization,
  getAuthorization,
  setAccountInfo,
  getAccountInfo,
  setSmallFishCallNumber,
  getSmallFishCallNumber,
  setDoctorRegisterInfo,
  getDoctorRegisterInfo,
  setDoctorAuthInfo,
  getDoctorAuthInfo,
  setWxInfo,
  getWxInfo,
  setLocalMsg,
  getLocalMsg,
  saveMsg,
  getMsg,
  getUserres,
  setUserres,
  setContact,
  getContact,
  setSouruce,
  getSouruce,
  removeAptId,
  setAptId,
  getAptId,
  setCardeStatus,
  getCardeStatus,
  setBackParam,
  getBackParam,
  removeBackParam,
  setNowCommon,
  getNowCommon,
  removeNowCommon,
  getNowAppointType,
  removeAppointType,
  setNowAppointType,
  setNavBarInfo,
  getNavBarInfo
}
